﻿namespace LinqEx.Tests
{
	using Microsoft.VisualStudio.TestTools.UnitTesting;
	using System;
	using System.Collections.Generic;
	using System.Linq;

	[TestClass]
	public class DictionaryExtensionTests
	{
		[TestMethod]
		public void Swap()
		{
			IDictionary<int, string> candidate = new Dictionary<int, string>()
			{
				{ 1, "one" },
				{ 2, "two" },
				{ 5, "five" }
			};

			IDictionary<string, int> result = candidate.Swap();

			Assert.AreEqual(candidate.Count, result.Count);

			Assert.AreEqual(1, result["one"]);
			Assert.AreEqual(2, result["two"]);
			Assert.AreEqual(5, result["five"]);
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Swap_SourceIsNull()
		{
			DictionaryExtensions.Swap<object, object>(null).GetEnumerator().MoveNext();
		}

		[TestMethod]
		public void FindKey()
		{
			IDictionary<int, string> candidate = new Dictionary<int, string>()
			{
				{ 1, "one" },
				{ 2, "two" },
				{ 5, "five" }
			};

			Assert.AreEqual(1, candidate.FindKey("one"));
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void FindKey_SourceIsNull()
		{
			DictionaryExtensions.FindKey<int, string>(null, null);
		}
	}
}
